<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>可编辑文字</title>
    <style>
        html,
        body,
        section,
        h2,
        ul,
        li,
        div,
        p,
        input,
        button {
            margin: 0;
            border: 0;
            padding: 0;
        }
        
        .clearfix::after {
            display: block;
            height: 0;
            content: '';
            visibility: hidden;
            clear: both;
        }
        
        section {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 300px;
            transform: translate(-50%, -50%);
            border: 1px solid #000000;
        }
        
        h2 {
            padding: 0 20px;
            height: 30px;
            line-height: 30px;
            font-size: 20px;
            background-color: #48C75D;
        }
        
        li {
            padding: 5px 20px;
            list-style-type: none;
            border-bottom: 1px solid #000000;
        }
        
        li:last-child {
            border-bottom: 0;
        }
        
        p {
            float: left;
            font-size: 14px;
            line-height: 22px;
        }
        
        button {
            float: left;
            margin-left: 20px;
            padding: 1px 5px;
            font-size: 14px;
            line-height: 20px;
            outline: none;
        }
        
        input {
            float: left;
            width: 100px;
            font-size: 14px;
            line-height: 20px;
            border: 1px solid #000000;
        }
        
        .hidden {
            display: none
        }
    </style>
</head>

<body>
    <section>
        <h2>分类名称</h2>
        <ul>
            <li class="clearfix">
                <div>
                    <p>喵哈世界</p>
                    <button>修改</button>
                </div>
                <div class="hidden">
                    <input type="text" name="" id="">
                    <button>确定</button>
                    <button>取消</button>
                </div>
            </li>
            <li class="clearfix">
                <div>
                    <p>喵喵女与二哈侠</p>
                    <button>修改</button>
                </div>
                <div class="hidden">
                    <input type="text" name="" id="">
                    <button>确定</button>
                    <button>取消</button>
                </div>
            </li>
        </ul>
    </section>
    <script>
        var aLi = document.getElementsByTagName('li');
        var fn = function(oLi) {
            var aDiv = oLi.getElementsByTagName('div');
            var aBtn = oLi.getElementsByTagName('button');
            var oIpt = oLi.getElementsByTagName('input')[0];
            var oP = oLi.getElementsByTagName('p')[0];
            aBtn[0].onclick = function() {
                oIpt.value = oP.innerHTML;
                aDiv[0].style.display = 'none';
                aDiv[1].style.display = 'block';
            }
            aBtn[1].onclick = function() {
                oP.innerHTML = oIpt.value;
                aDiv[1].style.display = 'none';
                aDiv[0].style.display = 'block';
            }
            aBtn[2].onclick = function() {
                aDiv[1].style.display = 'none';
                aDiv[0].style.display = 'block';
            }
        }

        for (var i = 0; i < aLi.length; i++) {
            fn(aLi[i]);
        }
    </script>
</body>

</html>